<template>
  <div class="loign-content">
    <div class="login-background">
      <div class="login-module">
        <div class="logn-title">
          <div class="login-icon"></div>
          <div class="big-title">金融代理系统</div>
        </div>
        <el-form class="login-form" ref="dataForm" :model="dataForm" :rules="rules">
          <el-form-item prop="phone">
            <el-input style="width: 100%;" v-model.trim="dataForm.phone" placeholder="请输入手机号码" prefix-icon="el-icon-user-solid"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input style="width: 100%;" v-model.trim="dataForm.password" type="password" placeholder="请输入登录密码" prefix-icon="el-icon-lock" @keyup.enter.native="onSubmit"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button :loading="logging" style="width:100%" @click="onSubmit" type="primary">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import api from './api'
import { CONSTANT_OBJ, kk } from '@/utils/constant'
import { setUserCookie } from '@/utils/auth'
import { getQueryParam } from '@/utils/util'
import {mapState} from 'vuex'
// import {aesEncrypt} from '@/utils/crypto'
export default {
  data () {
    return {
      logging: false,
      pwdDialog: false,
      dataForm: {
        userName: '',
        password: '',
        phone: '',
      },
      rules: {
        phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
        password: [{ required: true, message: '请输入登录密码', trigger: 'blur' }]
      }
    }
  },
  mounted () {
    this.getTenantId()
  },
  methods: {
    /**
     * @description 获取租户号并存cookie里
     */
    getTenantId () {
      let tenantId = getQueryParam('tenantId')
      setUserCookie({ tenantId })
    },
    /**
     * 提交
     */
    onSubmit () {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          let { phone, password } = this.dataForm
          let data = {
            phone,
            tenantId: getQueryParam('tenantId'),
            password: this.aes256(phone + password, kk)
          }
          console.log(data)
          api.postLoginData(data).then(res => {
            const { responseCode, data } = res
            if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
              console.log("data",data)
              this.$store.commit('common/GET_LOGIN_USER', data)
              setUserCookie(data)
              this.$router.push({ name: 'HOME' })
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.loign-content {
  height: 100%;
  background-color: rgba(242, 242, 242, 1);
  .login-background {
    background: url("../../../static/backgroundPicture.jpg") no-repeat;
    background-position: center bottom;
    height: 100%;
    width: 100%;
    position: fixed;
    bottom: 0px;
  }
  .login-module {
    width: 500px;
    height: 530px;
    background: #fff;
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 6px;
    box-shadow: 0 4px 10px #d6d6d6;
  }
  .logn-title {
    width: 100%;
  }
  .login-icon {
    margin-top: 40px;
    height: 120px;
    height: 120px;
  }
  .big-title {
    text-align: center;
    color: #0079fe;
    font-size: 36px;
  }
  .title {
    font-size: 18px;
    color: #0079fe;
    text-align: center;
  }
  .login-form {
    box-sizing: border-box;
    margin: 40px 0 60px;
    padding: 0 60px;
    position: relative;
  }
  .copyright {
    width: 100%;
    position: absolute;
    bottom: 10px;
    font-size: 12px;
    color: #ccc;
  }
  .copyright-item {
    text-align: center;
  }
}
</style>

<style lang="less">
.loign-content {
  .el-input__icon {
    font-size: 20px;
  }
}
</style>
